'''
选择排序:每次从剩余中找出最小/大,放到末尾/头部
时间复杂度: 最优O(n²)  最坏O(n²
稳定性:不稳定))
'''


def select_sort(list):
    n = len(list)
    for i in range(n - 1):
        min_index = i
        for j in range(i + 1, n):
            if list[min_index] > list[j]:
                min_index = j
        if i != min_index:
            list[i], list[min_index] = list[min_index], list[i]


if __name__ == '__main__':
    li = [31, 65, 12, 98, 54, 21, 100, 4]
    select_sort(li)
    print(li)
